<%@ page language="java" contentType="text/html; charset=utf-8"   pageEncoding="utf-8"%>
 <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
 <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script language="javascript" src="${basePath}commonJs/tags/My97DatePicker/WdatePicker.js"></script>  
<title>嘉童游乐中心-新增付款申请单</title>

	<SCRIPT type="text/javascript">
	var pkPayFormId ='${pkPayFormId}';
	$(document).ready(function(){
		initpriceSupRrd();
		purOrderPrdDiv('');
		
		
	});
	
	function process_sub(flag){
		var path ="";
		if(flag == 1){
			path = "${basePath}scmInvocing/scmPayForm/approvalProcessPayFormOrder.shtml";
		}else{
			path =  "${basePath}scmInvocing/scmPayForm/approvalProcessPayFormOrderExt.shtml";
		}
		$("#process_form_id").attr("action",path);
		$("#process_form_id").submit();
	}
	
	var pStatusName=new Array("未到货","部分到货","全部到货");
	function purOrderPrdDiv(divType){//采购商品目录 列表
		if(divType == 'divClose')
			{
				var isSelect = false;
				$("[name = codebox]:checkbox").each(function(){
					if($(this).attr("checked"))
						{
							isSelect = true;
						}
				});
				
				if(!isSelect)
					{
						alertInfo("请至少选择一项，或点击返回");
						return;
					}
			}
		var supplyId =$("#selectScmSupid").val();
	     var url="${basePath }scmInvocing/scmPayForm/scmPurOrderListSupIdAndByPayFormId.shtml?supplyId="+supplyId+"&pkPayFormId="+pkPayFormId;
			$.ajax({
				   url: url,
				   type: 'get',
				      async:false, 
				      success:function(data){
							if (data != null) {
								var jsonarray ;
								 for(var o in data){  
									 if(o=="scmPurOrderList"){
										 jsonarray=data[o];
										 var html='<tr><th>序号</th><th>采购订单编号</th><th>商品分类</th><th>到货状态</th><th>操作</th></tr>';
										 if(jsonarray!=null && jsonarray.length>0){
										 for (var k = 0; k < jsonarray.length; k++) {
												  var jsonobj = jsonarray[k];
										   if(jsonobj!=null){
											 var deliveryStatus =jsonobj["deliveryStatus"];
											 var deliveryName ="";
											 if(deliveryStatus!=null){
												 var deliveryStatusValue =parseInt(deliveryStatus)-1;
												 deliveryName =pStatusName[deliveryStatusValue];
											 }
											
											   
										      var pkPurordId=jsonobj["pkPurordId"];
										      var pCateName =jsonobj["pCateName"];
												 //===
						                               html+='<td>'+(k+1)+'</td>';
						                                html+='<td>'+pkPurordId+'</td>';
						                                html+='<td>'+pCateName+'</td>';
						                                html+='<td>'+deliveryName+'</td> ';
													var delpurPrd ="del_purOrderId('"+pkPurordId+"')";
													 html+='<td><input type="button" class="btn_l" onclick="'+delpurPrd+'" value="删除"/></td><input type="hidden" name="fkPurOrders" id="'+pkPurordId+'" value="'+pkPurordId+'"/>';
												 //===
												 html+="</tr>";
										  }
										 }   
										 }
										 $("#tablesupPrd").html(html);
									 } 
									
									
								 }
								
								 //initpriceSupRrd();//初始化 供应商 协议价格，协议id 
								 
							}else{
								 $.messager.alert('提示','添加采购商品失败！','error');
							}
							if(divType!=""){
							 $("#hide_loading").hide();
							 $('#addSelectGoods').window('close');
							}
					   }
			 });
	}
	
	function searchPurOrder(){
		var pkPurordIdSearch =$("#pkPurordIdSearch").val();
		if(pkPurordIdSearch!=""){
			$("#pkPurordId").val(pkPurordIdSearch);
		}else{
			$("#pkPurordId").val("");
		}
		var startTimeShow =$("#startTimeShow").val();
		var endTimeShow =$("#endTimeShow").val();
		if(startTimeShow !=""){
			$("#startApplyTime").val(startTimeShow);
		}else{
			$("#startApplyTime").val("");
		}
		
		if(endTimeShow !=""){
			$("#endApplyTime").val(endTimeShow);
		}else{
			$("#endApplyTime").val("");
		}
		var deliveryStatusShow =$("#deliveryStatusShow").val();
		$("#deliveryStatus").val(deliveryStatusShow);
		 initTab("form1", "table1", "foot1", initData);
	}
	
	function addPurPrd(){
		var supplyIds=$("#selectScmSupid").val();
		if(supplyIds==""){
			 alertWarning("请选择供应商！");
			 return;
		} else{
			$("#fkSupId").val(supplyIds);
			 initTab("form1", "table1", "foot1", initData);
			$('#addSelectGoods').window('open');
			
		}
	}
	function initTab(formId, tableId, footId, initData) {
		
		var form = $("#" + formId);
		var pagebean = new PageBean(form);
		pagebean.setCallback(initData);
		pagebean.setFootId(footId);
		pagebean.setTableId(tableId);
		setPagebeanObj(pagebean);
		pagebean.doPage();
	}
	
	function initData(data) { //初始化采购订单 列表
		
		if(data!=null){
			$.each(data,function(ind,obj){
				var indextd =ind+1;
				//var inputupdate ="getEditlUrl('"+obj.pkPurordId+"','edit')";
				var pCateName =obj.pCateName;
				if(pCateName ==null){
					pCateName ="";
				}
				var payFormorderId =obj.payFormorderId;
				var ischecked="";
				if(payFormorderId !="" && payFormorderId !=null){
					ischecked="checked";
				}
				 var deliveryStatus =obj.deliveryStatus;
				 var deliveryName ="";
				 if(deliveryStatus!=null){
					 var deliveryStatusValue =parseInt(deliveryStatus)-1;
					 deliveryName =pStatusName[deliveryStatusValue];
				 }
				 var htm="<tr>";
				htm+="<td><input type='checkbox' value="+obj.pkPurordId+" "+ischecked+" name='codebox' class='idFlag' onclick='SelectBoxOne(this)'></td>";
				htm+="<td>"+indextd+"</td>";
				htm+='<td>'+obj.pkPurordId+'</td>';
				htm+=' <td>'+pCateName+'</td>';
				htm+=' <td>'+deliveryName+'</td>';
				htm+="</tr>";
				 $("#table1").find("tr:eq("+ind+")").after(htm);
			});
		}
	}
	
	function SelectBoxOne(o){//单选 选中，或取消 采购订单列表 
		var supplyIds=$("#selectScmSupid").val();
	 
		var type="add";
	            if (o.type=="checkbox" && o.checked){      
	            }else{
	            	 type="cancel";      
	            }  
	     var url="${basePath }scmInvocing/scmPayForm/insertPayFormDetail.shtml?pkPayFormId="+pkPayFormId+"&pkPurordId="+o.value+"&type="+type+"&scmSupIds="+supplyIds;
			$.ajax({
				   url: url,
				   type: 'get',
				      async:false, 
				   success:function(msg){
						if (msg != "1") {
							 if(msg =="2"){
								 alertWarning("此采购订单暂时没有 供应商供货。请先添加供应商及供应商协议。");
							 }else{
								 alertWarning("选取采购订单失败。");
							 }
							 o.checked =false;
						}else{
						}
				   }
			 });
	}
	
	function selectAll(){//全选 选中，或取消采购订单列表 
		var type="add";
		var supplyIds=$("#selectScmSupid").val();
             var checklist = new Array();
             $("[name = codebox]:checkbox").each(function () {
            	
                 if ($("#chball").is(":checked")) {
                	 $("[name = codebox]:checkbox").attr("checked", true);
                 }else{
                	 type="cancel";   
                	   $(this).attr("checked", !$(this).attr("checked"));
                 }
                 checklist.push($(this).attr("value"));
             });

           //  checklist.join(",") ;
		 
		 if(checklist.length>0){

		    $("#hide_loading").show();
		    var url="${basePath }scmInvocing/scmPayForm/addPayFormOrderPrdBatch.shtml";
			$.ajax({
				   url: url,
				   type: 'post',
				   data:"pkPayFormId="+pkPayFormId+"&fkPurOrders="+checklist+"&type="+type+"&scmSupIds="+supplyIds,
				      async:false, 
				   success:function(msg){
						if (msg != "1") {
							 
						}else{
						}
						$("#hide_loading").hide();
				   }
			 });
			
		 }else{
			 //alertWarning("系统无商品。");
		 }
		}

	
	 function del_purOrderId(id){
		 $.messager.confirm('提示', '确认要删除吗?', function(r) {
			if(r){
				$.ajax({ 
					url: "${basePath }scmInvocing/scmPayForm/delScmPayformOrderByTwoId.shtml",
					data:"fkPurordId="+id+"&fkPayformId="+pkPayFormId,
					type:'POST',
					success: function(data){
						purOrderPrdDiv('');
						alertInfo($common_delete_success);
			      	}
				});
			}
		 });
	 }
	/**初始化 供应商 协议价格，协议id 
	**/
	function initpriceSupRrd(){//初始化 供应商 协议价格，协议id 
		 if('${oldSuppLyId}' != ''){
			 $("#selectScmSupid").val('${oldSuppLyId}');
			 refreshSelect();
		 }
			

		} 
	
	function selectSupId(oid){// 触发供应商 下拉框 onchange 事件
		 var value =$("#selectScmSupid").val();
		 if(value ==""){
			 alertWarning("请选择供应商。");
		 }else{
			 purOrderPrdDiv('');
			 refreshSelect();
		 }
	}
	
	function saveSupRrd(saveType,purStatus){
		var supplyIds=$("#selectScmSupid").val();
		if(supplyIds==""){
			 alertWarning("请选择供应商！");
			 return;
		} 
		 var url ='${basePath }scmInvocing/scmPayForm/savePurOrderPrdBatch.shtml?saveType='+saveType+'&pkPayFormId='+pkPayFormId+"&supplyId="+supplyIds+"&purStatus="+purStatus;
		
		 $.messager.confirm('提示', '确认提交吗?', function(r) {
				if(r){
					$.ajax({
				   url: url,
				   type: 'POST',
				   data:$("#supPrdForm").serialize(),//序列化表单里所有的内容
				      async:false, 
				   success:function(msg){
						if (msg != "1") {
							alertInfo("提交失败！");
						}else{
							//alertInfo("保存成功！");
							window.location.href='${basePath }scmInvocing/scmPayForm/findInvoOrderPay.shtml';
						}
				   }
			});
		
		}});
	}
	</SCRIPT>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
                <shiro:hasPermission name="scmInvocing/productInfo/forwardToProductInfo.shtml">
    				  <li><a href="${basePath}scmInvocing/productInfo/forwardToProductInfo.shtml"><i class="nav_icon_b"></i><br>商品信息</a></li>
    		</shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/countUnit/forwardToUnitInfo.shtml">
    		 		<li><a href="${basePath}scmInvocing/countUnit/forwardToUnitInfo.shtml"><i class="nav_icon_b"></i><br>单位设置</a></li>
    		 </shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/supplier/forwardToSupply.shtml">
    		 		   <li><a href="${basePath}scmInvocing/supplier/forwardToSupply.shtml"><i class="nav_icon_a"></i><br>供应商信息</a></li>
    		 </shiro:hasPermission>
    		  <shiro:hasPermission name="scmInvocing/priceManager/forwardToList.shtml">
    		 		  <li><a href="${basePath}scmInvocing/priceManager/forwardToList.shtml"><i class="nav_icon_f"></i><br>价格管理</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPurOrder/findInvoPurOrder.shtml">
            	  <li><a href="${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml"><i class="nav_icon_b"></i><br>采购订单</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPayForm/findInvoOrderPay.shtml">
           		   <li  class="content_hover"><a href="${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml"><i class="nav_icon_b"></i><br>付款申请</a></li>
    		 </shiro:hasPermission></ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
            <div class="file_single_dl f14 fixed">
                <h1 class=""><font size="+1">付款申请单</font></h1>
                <hr>
                <dl class="fixed" style="overflow:hidden"> 
                    <dd>
                    <label>付款申请编号：</label>
                     <c:choose>
		                  <c:when test="${type=='add'}">
		                  		 ${pkPayFormId} 
		                   </c:when>
		                    <c:otherwise>
		                          ${pkPayFormId} 
		                     </c:otherwise>
                      </c:choose>
                   
                    </dd>
               		<dd><label>申请人：</label>${userName}</dd>
               		<dd><label>申请门店：</label>${brandName}</dd>
                </dl>
                <hr>
				<dl  class="fixed" style="overflow:hidden">
	    	       <dd>
                    <label>供应商：</label> 
                     <div class="uboxstyle"> 
                           <select name="selectScmSupid" id="selectScmSupid" onchange="selectSupId(this)">
                            <option value="">请选择供应商</option>
                            <c:forEach items="${scmSupList}" var="scmSupply" varStatus="status">
			                        <option value="${scmSupply.pkSupId}" >${scmSupply.supName}</option>
                             </c:forEach>
                           </select>
                       </div>
                    </dd>
                          
             </dl>
                <hr>
            </div>
                     <dl class="fixed order_dl">
                         	<!-- <dd><label><b>当前步骤：</b></label>总监审批</dd> -->
							<dd><label><b>处理历史：</b></label>
                        	<dd>
                            <table class="table" >
                                <tr>
                                    <th>时间</th>
                                    <th>处理人</th>
                                    <th>结果</th>
                                    <th>处理意见</th>
                                </tr>
                                 <c:forEach items="${hisWorkFlowList }" var="hisEntity" >
			                        <tr>
	                                    <td style="width:40%">${hisEntity.optTime }</td>
	                                    <td>${hisEntity.optName }</td>
	                                    <td>${hisEntity.result }</td>
	                                    <td><input type="text" disabled value="${hisEntity.advice }" class="iput_t w100"></td> 
	                                </tr>
		                        </c:forEach>
                            </table>
                        </dd>
  
            	
            	</dl>
            <div class="mt10">
                <h1 class=""><font size="+1">采购订单目录</font></h1>
                <ul class="fixed" id="tab_conbox_a">
                    <li class="p10 h450">
                    <form action="" id="supPrdForm">
                        <table class="table" id="tablesupPrd">
                            
                        </table>
                     </form>
                        <div class="btm_btn m10">
                            <dl>
                            	<dd><input class="btn" type="button" value="新增" onClick="addPurPrd()"></dd>
                                <dd><input class="btn" type="button" value="提交" onClick="saveSupRrd('tijiao','2')"></dd>
                                <dd><input class="btn" type="button" value="返回" onClick="javascript:window.location.href='${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml'"></dd>
 
                                <!-- <dd><input class="btn" type="button" onclick="saveSupRrd('save','1')" value="保存"></dd> -->
 
                               <dd><input class="btn" type="button" value="打印" ></dd>
                            </dl>
                        </div>
                            
                          
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<!---弹出层 成员信息编w辑--->
<div id="addSelectGoods" class="easyui-window" title="新增付款申请单" data-options="modal:true,closed:true,iconCls:'icon-save'" style="width:1190px; height:400px;position:relative;">
	<div class="content m_auto">

    <div class="content_r mt10" style="height:340px !important; min-height:340px !important;margin-left: 10px !important;">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
        	<dl class="fixed" style="overflow:hidden">
            	<dd><label>采购订单编号：</label><input type="text" id="pkPurordIdSearch" class="iput_t w200"></dd>
                <dd style="width:700px !important;"><label>采购申请时间：</label>
                <input type="text" id="startTimeShow" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true})" class="Wdate iput_t w150">
				<span>至</span>
				<input type="text" id="endTimeShow" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true})" class="Wdate iput_t w150">                </dd>
                <dd>
                	<label>到货状态：</label><div class="uboxstyle">
					<select name="deliveryStatus"  id="deliveryStatusShow">
						 <option value="">请选择</option> 
                         <option value="3">全部到货</option>
                         <option value="1">未到货</option>
                         <option value="2">部分到货</option>
                     </select>
                   </div>
                </dd>
            	<dd class="fr"><input type="button" class="btn fr" onclick="searchPurOrder()" value="查询"></dd>
            </dl>
        </div>
       
        <div class="tab_normal mt10">
 <form action="${basePath}scmInvocing/scmPayForm/findScmPurOrderPayForm.shtml" method="post" id="form1">
                  <input type="hidden" name="pageSize" value="10"> <input type="hidden" name="pageNo" value="1">
                  <input type="hidden" name="pkPurordId" id="pkPurordId">
                  <input type="hidden" name="fkSupId" id="fkSupId" value="${oldSuppLyId}">
                  <input type="hidden" name="fkPayFormId" id="fkPayFormId" value="${pkPayFormId}">
                   <input type="hidden" name="deliveryStatus" id="deliveryStatus">
                    <input type="hidden" name="startApplyTime" id="startApplyTime" >
                  <input type="hidden" name="endApplyTime" id="endApplyTime">
                	<table class="table" id="table1">
                    	<tr> 
                       		<th><input type="checkbox" id="chball"    onclick="selectAll()"/></th>
                        	<th>序号1</th>
                            <th>采购订单编号</th>
                            <th>商品分类</th>
                            <th>到货状态</th>
                        </tr>
                         
                       
                    </table>
                  
                    <!---翻页-->
                    <div class="page fr m10">
                    	<div class="btm_btn mt10">
                            <dl>
                              <dd><input class="btn" type="button" value="确定" onclick="purOrderPrdDiv('divClose');"></dd>
                              <dd><input class="btn" type="button" value="返回" onclick="$('#addSelectGoods').window('close')"></dd>
                               <dd style="width:50px">&nbsp;</dd>
                                <dd style="width:50px">&nbsp;</dd>
                                 <dd style="width:50px">&nbsp;</dd>
                                <dd>
                                   <div id="foot1"></div>
                                </dd>
                            </dl>
                        </div>
                    	
                      
                    </div>
                    <!----->
        </form>
                </div>
        </div>
    </div>
</div> 
    
</div>
</body>
</html>